cmake_minimum_required(VERSION 3.0.0)
project(hello VERSION 0.1.0 LANGUAGES C CXX)

# 获取当前时间
string(TIMESTAMP BUILD_TIME "%Y-%m-%d %H:%M:%S")

# 查找Git，并获取最新的commit ID
#COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD  #输出短id
find_package(Git QUIET)
if(GIT_FOUND)
  execute_process(
    COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    OUTPUT_VARIABLE GIT_COMMIT
    OUTPUT_STRIP_TRAILING_WHITESPACE
  )
else()
  set(GIT_COMMIT "unknown")
endif()

# 添加宏定义，这样可以在代码中访问
add_definitions(-DBUILD_TIME="${BUILD_TIME}")
add_definitions(-DGIT_COMMIT="${GIT_COMMIT}")
message(STATUS "创建时间是 ${BUILD_TIME}")
message(STATUS "生成时提交id为 ${GIT_COMMIT}")

# add_subdirectory(01_leds)

#################################
#   make VERBOSE=1 #可以显示构建时的细节
#
#
#
#################################